import { TimeObserver } from "./TimeObserver";
import TimeHelper from "./TimeHelper";

/**
 * 时间递增
 */
export class TimerIncremental extends TimeObserver {
    protected temp: number = 0;
    /**
     * 一定要小于当前时间才有意义。
     * @param startTime 经过的时间
     */
    setTime(startTime: number) {
        this.time = Math.floor(TimeHelper.startTime(startTime) / 1000);
    }

    check(dt: number) {
        this.temp += dt;
        if (this.temp >= this.duration) {
            let per = Math.floor(this.temp / this.duration)
            this.temp -= per
            this.time += per
            // this.temp -= this.duration
            // this.time += this.duration
            if (this.func) {
                this.func(this.time);
            }
        }
        return false
    }
}